package org.scrumfx;

import org.scrumfx.bean.Project;
import org.scrumfx.business.ProjectBusiness;
import org.scrumfx.dal.ProjectDAL;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SandBoxMain
{
  public static void main(String[] args)
  {
    // declaration
    ProjectDAL projectDAL = new ProjectDAL();

    // count
    System.out.println("Nombre de projets = " + projectDAL.count());

    // save
    Project projectSave = new Project();
    projectSave.setLongName("project_long_name");
    projectSave.setShortName("PSN");

    Project projectPersisted = projectDAL.saveProject(projectSave);
    System.out.println("Identifiant du nouveau projet = "
        + projectPersisted.getId());
    System.out.println("Apres ajout d'un projet, nombre de projets = "
        + projectDAL.count() + " (attendu 6)");

    // get
    Project projectGet = projectDAL.getProject(projectPersisted.getId());
    System.out.println("Nom complet du projet = " + projectGet.getLongName());

    // update
    projectGet.setLongName("nouveau_nom");

    Project updatedProject = projectDAL.saveProject(projectGet);
    System.out.println("Apres mise a jour du projet, nombre de projets = "
        + projectDAL.count() + " (attendu 6)");

    // delete
    projectDAL.deleteProject(updatedProject);
    System.out.println("Apres suppression du projet, nombre de projets = "
        + projectDAL.count() + " (attendu 5)");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    ProjectBusiness pb = (ProjectBusiness) context.getBean("projectBusiness");
    Project myProject = pb.getProject(1);
    System.out.println(myProject.getLongName());
  }

}
